# from Net Mirror project
import pcap

class NMpcap:
	def __init__(self,dev,filter,prn):

		self.dev=dev
		self.filter=filter
		self.p=pcap.pcapObject()
		self.p.open_live(self.dev, 1600, 0, 100)
		self.p.setfilter(self.filter, 0, 0)
		self.prn=prn

	def dispatch(self,count=0):
		try:
			while 1:
				self.p.dispatch(count,self.prn)
		except:
			print "Error dispatching packets from python-libpcap. Exiting"
			exit(500)

def print_packet(plen,pdata,pts):
	print "Len: "+str(plen)+" Data: "+str(pdata)+ " Pts: "+ str(pts)

pcapmirror=NMpcap("ath0","tcp port 80", print_packet)
pcapmirror.dispatch()	          


#Net Mirror (c) 2009 Pablo Rincon Crespo

